<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<form action="<?php echo url_for('citas/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id_cita='.$form->getObject()->getIdCita() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>
  <table>
    <tfoot>
      <tr>
        <td colspan="2">
          <?php echo $form->renderHiddenFields(false) ?>
          &nbsp;<a href="<?php echo url_for('citas/index') ?>">Back to list</a>
          <?php if (!$form->getObject()->isNew()): ?>
            &nbsp;<?php echo link_to('Delete', 'citas/delete?id_cita='.$form->getObject()->getIdCita(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
          <?php endif; ?>
          <input type="submit" value="Save" />
        </td>
      </tr>
    </tfoot>
    <tbody>
      <?php echo $form->renderGlobalErrors() ?>
      <tr>
        <th><?php echo $form['fecha']->renderLabel() ?></th>
        <td>
          <?php echo $form['fecha']->renderError() ?>
          <?php echo $form['fecha'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['hora']->renderLabel() ?></th>
        <td>
          <?php echo $form['hora']->renderError() ?>
          <?php echo $form['hora'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['fecha_entrega']->renderLabel() ?></th>
        <td>
          <?php echo $form['fecha_entrega']->renderError() ?>
          <?php echo $form['fecha_entrega'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['hora_entrega']->renderLabel() ?></th>
        <td>
          <?php echo $form['hora_entrega']->renderError() ?>
          <?php echo $form['hora_entrega'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['hora_preferida']->renderLabel() ?></th>
        <td>
          <?php echo $form['hora_preferida']->renderError() ?>
          <?php echo $form['hora_preferida'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['detalles']->renderLabel() ?></th>
        <td>
          <?php echo $form['detalles']->renderError() ?>
          <?php echo $form['detalles'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['observacion']->renderLabel() ?></th>
        <td>
          <?php echo $form['observacion']->renderError() ?>
          <?php echo $form['observacion'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['detalles_usuario']->renderLabel() ?></th>
        <td>
          <?php echo $form['detalles_usuario']->renderError() ?>
          <?php echo $form['detalles_usuario'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['status']->renderLabel() ?></th>
        <td>
          <?php echo $form['status']->renderError() ?>
          <?php echo $form['status'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['is_aceptado']->renderLabel() ?></th>
        <td>
          <?php echo $form['is_aceptado']->renderError() ?>
          <?php echo $form['is_aceptado'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['is_pending']->renderLabel() ?></th>
        <td>
          <?php echo $form['is_pending']->renderError() ?>
          <?php echo $form['is_pending'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['id_usuario']->renderLabel() ?></th>
        <td>
          <?php echo $form['id_usuario']->renderError() ?>
          <?php echo $form['id_usuario'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['id_vehiculo_usuario']->renderLabel() ?></th>
        <?php if (!$form->getObject()->isNew()): ?>
        <td>
          <?php echo $form['id_vehiculo_usuario']->renderError() ?>
          <?php //echo $form['id_vehiculo_usuario'] ?>
          <?php
          $query = Doctrine_Query::create()
                    ->select("*")
                    ->from("VehiculoUsuario s")
                    ->where("s.id_usuario = " . $form->getObject()->getIdUsuario());

          $q = new sfWidgetFormDoctrineChoice(array('model' => 'VehiculoUsuario',
                'query' => $query, 'default' => $form->getObject()));

          echo $q->render('cita[id_vehiculo_usuario]'); ?>
        </td>
        <?php else : ?>
        <td>
          <?php echo $form['id_vehiculo_usuario']->renderError() ?>
          <?php echo $form['id_vehiculo_usuario'] ?>
        </td>
        <?php endif; ?>
      </tr>
      <?php if ($sf_user->hasCredential('Admin')) : ?>
      <tr>
        <th><?php echo $form['id_vendedor']->renderLabel() ?></th>
        <td>
          <?php echo $form['id_vendedor']->renderError() ?>
          <?php echo $form['id_vendedor'] ?>
        </td>
      </tr>
      <?php else : ?>
      <tr>
        <th></th>
        <td>
          <?php echo $form['id_vendedor']->renderError() ?>
          <input type="hidden" name="cita[id_vendedor]" id="cita_id_vendedor" value="<?php echo $sf_user->getAttribute('id_usuario') ?>" />
        </td>
      </tr>
      <?php endif; ?>
      <tr>
        <th><?php echo $form['servicios_list']->renderLabel() ?></th>
        <td>
          <?php echo $form['servicios_list']->renderError() ?>
          <?php echo $form['servicios_list'] ?>
        </td>
      </tr>
    </tbody>
  </table>
</form>
